package edu.zut.main.thread;

public class ThreadSleep2 {

    public static void main(String[] args) {
        TicketThread ticketThread = new TicketThread();
        new Thread(ticketThread,"售票员A").start();
        new Thread(ticketThread,"售票员B").start();
        new Thread(ticketThread,"售票员C").start();
    }

}
//利用多线程模拟售票,如何控制余票   后期再添加
class TicketThread implements Runnable{
    //余票
    private int ticketNum = 10;
    //售票任务
    @Override
    public void run() {
        while (true){
            //如果余票不足，停止
            if (ticketNum <= 0){
                break;
            }
            //模拟延时
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "卖了第"+ticketNum-- +"张票");
        }
    }
}







